/**   
 * @Title: HorizontalListAdapter.java 
 * @Package: com.rename.icode.view 
 * @Description: Administrator版权所有
 * @author Administrator  
 * @date 2015-3-11 下午4:21:52 
 * @version  
 */

package com.rename.icode.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.rename.icode.R;
import com.rename.icode.model.CodeFile;
import com.rename.icode.utils.LogUtil;

import java.util.List;

/**
 * @Description 水平List适配器
 * @author Administrator
 * @date 2015-3-11 下午4:21:52
 * @version V1.0
 */

public class HorizontalListAdapter extends BaseAdapter {

	private static final String TAG = "HorizontalListAdapter";
	
	private Context mContext;
	private LayoutInflater mInflater;
	private List<CodeFile> mCodeFiles = null;

	public HorizontalListAdapter(Context context, List<CodeFile> codeFiles) {
		this.mContext = context;
		this.mCodeFiles = codeFiles;
		mInflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return mCodeFiles.size();
	}

	@Override
	public Object getItem(int position) {
		return mCodeFiles.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		CodeFile codeFile = mCodeFiles.get(position);

		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = mInflater.inflate(R.layout.selected_file_item, null);
			holder.mTextView = (TextView) convertView
					.findViewById(R.id.selected_file_name_txt);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		holder.mTextView.setTag(codeFile);
		holder.mTextView.setText(codeFile.getName());
		LogUtil.i(TAG, "selected codefile name==>" + holder.mTextView.getText());
		return convertView;
	}

	private static class ViewHolder {
		private TextView mTextView;
	}

}
